import Vue from "vue"
import VueRouter from "vue-router"
import ProLayout from "@/components/layout/pro-layout"
import Home from "@/views/home"

const RouteView = {
	name: "RouteView",
	render: (h) => h("router-view"),
}

Vue.use(VueRouter)

// 自定义icon使用meta.icon，官网自带的icon用icon
const asyncRouterMap = [
	{
		path: "/",
		name: "ProLayout",
		component: ProLayout,
		redirect: "/home",
		children: [
			{
				path: "/home",
				name: "home",
				icon: "home",
				meta: {
					title: "主页",
				},
				component: Home,
			},
			{
				path: "/table",
				name: "table",
				meta: {
					title: "表格",
					icon: "table",
				},
				component: RouteView,
				redirect: "/table/baseTable",
				children: [
					{
						path: "/table/baseTable",
						name: "baseTable",
						meta: {
							title: "展示型表格",
						},
						component: () => import("@/views/table/baseTable"),
					},
					{
						path: "/table/searchTable",
						name: "searchTable",
						meta: {
							title: "功能型表格",
						},
						component: () => import("@/views/table/searchTable"),
					},
				],
			},
			{
				path: "/form",
				name: "form",
				icon: "form",
				meta: {
					title: "表单",
				},
				component: RouteView,
				redirect: "/form/divForm",
				children: [
					{
						path: "/form/divForm",
						name: "divForm",
						meta: {
							title: "自定义表单",
						},
						component: () => import("@/views/divForm/index"),
					},
				],
			},
		],
	},
]

const constantRouterMap = [
	{
		path: "/404",
		component: () =>
			import(/* webpackChunkName: "fail" */ "@/views/exception/404"),
	},
]

const router = new VueRouter({
	mode: "hash",
	base: process.env.BASE_URL,
	routes: constantRouterMap.concat(asyncRouterMap),
})

export default router
